package com.coin900.coin.server.exception;

import org.springframework.web.servlet.ModelAndView;

import java.util.Iterator;
import java.util.Map;


/**
 * Unibon
 * <p/>
 * Copyright (c) 2012 YouPeng ValueSoft Inc., All rights reserved.
 * <p/>
 * This software is the confidential and proprietary information of
 * ValueSoft Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with ValueSoft.com.
 * <p/>
 * Revision History
 * Date      		Programmer       Notes
 * 13-8-30   	     laborc		     Initial
 * *********************************************************************
 */
public class ExceptionResponse {
    public static String SUCCESS = "1000";
    public static String FAIL = "0000";

    public ExceptionResponse() {

    }

    protected ModelAndView view;

    public ExceptionResponse(ModelAndView view) {
        this.view = view;
        this.setResponseCode(ExceptionResponse.SUCCESS);
    }

    /**
     * 响应代号
     */
    private String responseCode;
    /**
     * 信息
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    public String getResponseCode() {
        return responseCode;
    }

    public void setResponseCode(String responseCode) {
        this.responseCode = responseCode;
        view.addObject("responseCode", responseCode);
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
        view.addObject("data", data);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
        view.addObject("message", message);
    }

    public void setMap(Map<String, Object> params) {
        if (params != null) {
            Iterator<Map.Entry<String, Object>> it = params.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                view.addObject(entry.getKey(), entry.getValue());
            }
        }
    }
}
